import RequestManager from "../../request/request-manager";
import api from "../../config/api";

const PKG_NAME='WMI';
const REQUEST_LOADING = `${PKG_NAME}/REQUEST_LOADING`;
const RESET = `${PKG_NAME}/RESET`;
const LOAD_VIN_APPLICATION_LIST_SUCCESS = `${PKG_NAME}/LOAD_VIN_APPLICATION_LIST_SUCCESS`;
const requestLoading = () =>{
     return {
         type: REQUEST_LOADING
     }
};
const reset = () => {
    return {
        type: RESET
    }
};

const loadVinApplications = (page, pageSize) =>{
    return listVinApplications(api.vin_applications_list, page, pageSize);
};

const listVinApplications = (url, page, pageSize) =>{
    return async (dispatch) =>{
        dispatch(requestLoading());
        try {
            const response =await RequestManager.get(url).queryString({
                page: page,
                pageSize: pageSize || 10
            }).execute();
            if (response.code === 200) {
                dispatch(loadVinApplicationsSuccess(response.data))
            }
        } catch (e) {

        }
    }
};
const loadVinApplicationsSuccess= (payload)=> {
    return {
        type: LOAD_VIN_APPLICATION_LIST_SUCCESS,
        payload: payload
    }
}

export  {
    REQUEST_LOADING,
    RESET,
    LOAD_VIN_APPLICATION_LIST_SUCCESS,
    reset,
    requestLoading,
    loadVinApplications
}

